package khs.java_vlcj_movie_player.main.java;

import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;

import com.sun.jna.NativeLibrary;

import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

/**
 * Hello world!
 *
 */
public class App 
{
    private static JFileChooser fileSelector = new JFileChooser();
    
    private JFrame jFrame = new JFrame();
    private EmbeddedMediaPlayerComponent mediaPlayerComponent;
    private String mediaPath = "";
    
    App(String vlcPath, String mediaURL){
        mediaPath = mediaURL;
        NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcPath);
        mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
        jFrame.setContentPane(mediaPlayerComponent);
        jFrame.setSize(1200, 800);
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    
    public void run(){
        mediaPlayerComponent.getMediaPlayer().playMedia(mediaPath);
    }
    
    public static void main( String[] args )
    {
        String vlcPath = "";
        String mediaPath = "";
        File ourFile;
        
        fileSelector.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fileSelector.showSaveDialog(null);
        ourFile = fileSelector.getSelectedFile();
        vlcPath = ourFile.getAbsolutePath();
        
        fileSelector.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileSelector.showSaveDialog(null);
        ourFile = fileSelector.getSelectedFile();
        mediaPath = ourFile.getAbsolutePath();
        
        new App(vlcPath, mediaPath).run();
    }
}
